import { ref } from 'vue'
import { defineStore } from 'pinia'
import { userLoginService } from '@/api/user.js'

export const useUserStore = defineStore(
  'big-user',
  () => {
    const token = ref('')

    const user = ref({})

    const phone = ref('')
    const password = ref('')

    const getUser = async () => {
      const res = await userLoginService({
        phone: phone.value,
        password: password.value
      })
      token.value = res.data.data.token
      user.value = res.data.data
    }

    return { token, user, phone, password, getUser }
  },
  { persist: true }
)
